package com.sqx.modules.creation.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.creation.entity.dto.AddCommentDto;
import com.sqx.modules.creation.entity.dto.AddCommentReplyDto;
import com.sqx.modules.creation.service.CreationCommentService;
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import net.dreamlu.mica.ip2region.core.IpInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/app/creation/comment")
public class AppCreationCommentController {
    @Autowired
    private CreationCommentService creationCommentService;

    @Autowired
    private Ip2regionSearcher ip2regionSearcher;

    /**
     * 添加评论
     * @param userId
     * @param addCommentDto
     * @return
     */
    @PostMapping("/addComment")
    @Login
    public Result addComment(@RequestAttribute("userId")Long userId, @RequestBody@Valid AddCommentDto addCommentDto) {
        return creationCommentService.addComment(userId, addCommentDto);
    }

    /**
     * 添加评论回复
     * @param userId
     * @param addCommentReplyDto
     * @return
     */
    @PostMapping("/addCommentReply")
    @Login
    public Result addCommentReply(@RequestAttribute("userId")Long userId, @RequestBody@Valid AddCommentReplyDto addCommentReplyDto) {
        return creationCommentService.addCommentReply(userId, addCommentReplyDto);
    }

    /**
     * 获取评论列表
     * @param userId
     * @param creationId
     * @return
     */
    @GetMapping("/getCommentList")
    @Login
    public Result getCommentList(@RequestAttribute("userId")Long userId,Long creationId,Integer page,Integer limit) {
        return creationCommentService.getCommentList(userId,creationId,page,limit);
    }

    /**
     * 获取回复列表
     * @param commentId
     * @return
     */
    @Login
    @GetMapping("/getReplyList")
    public Result getReplyList(@RequestAttribute("userId")Long userId,Long commentId,Integer page,Integer limit) {
        return creationCommentService.getReplyList(userId,commentId,page,limit);
    }

    /**
     * 根据评论id查询评论详情
     * @param commentId
     * @return
     */
    @Login
    @GetMapping("/selCommentById")
    public Result selCommentById(Integer commentId){
        return creationCommentService.selCommentById(commentId);
    }


}
